var vue=new Vue({
    el:'#main',
    data:{
        pageInfo:{}
    },
    methods:{
        selectPage:function (pageNum,pageSize) {
            axios({
                url:`/role/selectPage/${pageNum}/${pageSize}`
            }).then(response =>{
                this.pageInfo=response.data.obj;
            }).catch(error => {
                console.log(error);
            })
        },
        toUpdate:function (id) {
            layer.obj=id;
            layer.message='';
            layer.open({
                type:2,
                title:false,
                area:['70%','65%'],
                content:'/role/toUpdate',
                end: ()=> {
                    if (layer.message!=''){
                        layer.msg("更新成功");
                        this.selectPage(this.pageInfo.pageNum,this.pageInfo.pageSize);
                    }
                }
            })
        },
        doDelete:function (Rid) {
            axios({
                url:`/role/doDelete/${Rid}`,
            }).then(response=>{
                if (response.data.success){
                    layer.msg("删除成功");
                    this.selectPage(this.pageInfo.pageNum,this.pageInfo.pageSize);
                }else {
                    layer.msg("删除失败");
                }
            }).catch(error=>{
                layer.msg(error.message);
            })
        },
        toInsert:function () {
            layer.message='';
            layer.open({
                type:2,
                title:false,
                area:['70%','65%'],
                content:'/role/toInsert',
                end: ()=> {
                    if (layer.message!=''){
                        layer.msg("添加成功");
                        this.selectPage(this.pageInfo.pageNum,this.pageInfo.pageSize);
                    }
                }
            })
        }
    },
    created:function () {
        this.selectPage(1,5);
    }
});